package com.axin.web.controller;

import com.axin.blog.api.RemoteBlogService;
import com.axin.blog.api.vo.BlogVo;
import com.axin.common.core.domain.web.AjaxResult;
import com.axin.common.core.domain.web.TableDataInfo;
import com.axin.web.annotation.IgnoreAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author axin
 * @Date 2021/10/31 14:11
 **/
@RestController
@RequestMapping("/blog")
public class ApiBlogController {


    @Autowired
    private RemoteBlogService remoteBlogService;

    /**
     * 获取最新发布的博客
     *
     * @return
     */
    @IgnoreAuth
    @GetMapping("/getNewBlog")
    public TableDataInfo getNewBlog(@RequestParam("pageNum") Integer pageNum,
                                    @RequestParam("pageSize") Integer pageSize,
                                    @RequestParam(name = "createMonth", required = false, defaultValue = "") String createMonth,
                                    @RequestParam(name = "categoryId", required = false, defaultValue = "") Long categoryId,
                                    @RequestParam(name = "tagId", required = false, defaultValue = "") Long tagId) {
        return remoteBlogService.getNewBlogPageList(pageNum, pageSize, createMonth, categoryId, tagId);
    }


    /**
     * 根据博客ID获取详情
     *
     * @return
     */
    @IgnoreAuth
    @GetMapping("/getBlogDetail/{blogId}")
    public AjaxResult<BlogVo> getBlogDetail(@PathVariable("blogId") Long blogId) {
        return remoteBlogService.getBlogDetail(blogId);
    }


    /**
     * 获取日期（月份）归档
     *
     * @return
     */
    @IgnoreAuth
    @GetMapping("/getMonthArchiveList")
    public AjaxResult getMonthArchiveList() {
        return remoteBlogService.getMonthArchiveList();
    }
}
